package top.lilele.adminSystem.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.lilele.adminSystem.dto.IdsParams;
import top.lilele.adminSystem.entity.AdminMapEntity;
import top.lilele.adminSystem.service.AdminMapService;
import top.lilele.adminSystem.utils.BaseResponse;
import top.lilele.adminSystem.utils.ResponseCodeEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lilele
 */
@Api(tags = "数据字典")
@RestController
@RequestMapping(value = "map")
public class AdminMapController {
    @Resource
    AdminMapService adminMapService;

    @ApiOperation(value = "新增数据字典")
    @PostMapping(value = "addMap")
    public BaseResponse add(@RequestBody List<AdminMapEntity> list) {
        adminMapService.addMap(list);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "查询公数据字典")
    @GetMapping(value = "queryMapList")
    public BaseResponse queryMapList() {
        return BaseResponse.info(ResponseCodeEnum.Success, adminMapService.queryMapList());
    }

    @ApiOperation(value = "更新数据字典")
    @PostMapping(value = "updateMap")
    public BaseResponse updateMapById(@RequestBody @Validated AdminMapEntity adminMapEntity) {
        adminMapService.updateMap(adminMapEntity);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "删除数据字典--包含批量与单个")
    @PostMapping(value = "deleteMap")
    public BaseResponse deleteMap(@RequestBody @Validated IdsParams idsParams) {
        adminMapService.deleteMap(idsParams.getIds());
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

}
